package LinkedList.奇偶链表;

import LinkedList.ListNode;

public class Test {
    public ListNode oddEvenList(ListNode head) {
        ListNode dummy1 = new ListNode(-1);
        ListNode dummy2 = new ListNode(-1);
        ListNode cur1 = dummy1, cur2 = dummy2;
        int count = 1; // 计数器，用来判断是奇还是偶
        while(head != null) {
            if(count % 2 == 1) {
                cur1.next = head;
                head = head.next;
                cur1 = cur1.next;
                count ++;
            }else{
                cur2.next = head;
                head = head.next;
                cur2 = cur2.next;
                count ++;
            }
        }
        cur2.next = null;
        cur1.next = dummy2.next;

        return dummy1.next;
    }
}
